function displayTreeInfo( p ) {

    if( p.name.length > 40 ) { p.name = p.name.substr(0, 40) + '...'; }

    var anchorInfo = [ { 'attr': { 'href': makeAjaxURL( { argList: [ 'viewer', p.id ] } ) },
                         'text': 'view' },
                       
                       { 'attr': { 'href': makeAjaxURL( { argList: [ 'grafter', p.id ] } ) },
                         'text': 'graft onto' },

                       { 'attr': { 'href': 'javascript:void(0);' },
                         'bind': [ 'click', { id: p.id }, ajaxDeleteTree ],
                         'text': 'delete' } ];

    var linkContainer = makeEl('div').attr( { 'class': 'width10 fLeft smallText' } );

    for( var i = 0, ii = anchorInfo.length; i < ii; i++ ) {

        var anchor = makeEl('a').attr( anchorInfo[i].attr ).text( anchorInfo[i].text );
        
        if( anchorInfo[i].bind ) { anchor.bind( anchorInfo[i].bind[0], anchorInfo[i].bind[1], anchorInfo[i].bind[2] ); }

        linkContainer.append( makeEl('div').attr( { 'class': 'center' } ).append( anchor ) );
    }

    $('#treeContainer').append(
        makeEl('div').attr( { 'id': 'tree' + p.id, 'class': 'fullwidth', 'treeId': p.id } )
            .append( linkContainer, 
                     makeEl('div').attr( { 'class': 'width30 fLeft center' } ).text( p.name ),
                     makeEl('div').attr( { 'class': 'width30 fLeft center' } ).text( p.creationDate ),
                     makeEl('div').attr( { 'class': 'width30 fLeft center' } ).text( p.type ),
                     makeEl('div').attr( { 'class': 'clear' } ) ) );
}

function newickFileSelected() {
    $('#newickString').hide();
    $('#newickFileSelectedNotice').removeClass('hide');
    $('#cancelNewickFileUploadLink').removeClass('hide');
    $('#shadowboxSubmitButton').unbind('click').click( submitFileUploader );
}

function submitFileUploader() { globals.uploader.submit(); }
function newickStringAjaxUpload() { ajaxAddNewick(); }

function showNewickStringUploadDialogue() {
    $('#newickString').show();
    $('#newickFileSelectedNotice').addClass('hide');
    $('#cancelNewickFileUploadLink').addClass('hide');
    $('#shadowboxSubmitButton').unbind('click').click( newickStringAjaxUpload );
}

function removeTree(id) { $('#tree'+id).fadeOut('slow', function() { $('#tree'+id).remove(); } ); }

function loginDialogue() { alert('Please login first.'); }

function createSourceTreeInfoContainer() {

    $('#sourceTreeContainer').append(
        makeEl('div').attr( { 'id': 'sourceTreeHeader', 'class': 'fCenter greenBackground white' } ).append(
            makeEl('div').attr( { 'class': 'leftMargin10 center fLeft width30' } ).text('name'),
            makeEl('div').attr( { 'class': 'center fLeft width60' } ).text('comments'),
            makeEl('div').attr( { 'class': 'clear' } ) ),
        makeEl('div').attr( { 'id': 'sourceTrees', class: 'fCenter' } ) );
}


function createGraftedTreeInfoContainer() {

    $('#treeInfoContainer').append(
        makeEl('div').attr( { 'id': 'graftedTreeContainer' } ).append(

            makeEl('div').attr( { 'id': 'graftedTreeTitle' } ).append(
                makeEl('div').attr( { 'class': 'fLeft rightMargin1' } ).text('Grafed Trees'),
                makeEl('div').attr( { 'class': 'clear' } ) ) ),

            makeEl('div').attr( { 'id': 'graftedTreeHeader', 'class': 'fCenter greenBackground white' } ).append(
                    makeEl('div').attr( { 'class': 'leftMargin10 center fLeft width30' } ).text('name'),
                    makeEl('div').attr( { 'class': 'center fLeft width60' } ).text('comments'),
                    makeEl('div').attr( { 'class': 'clear' } ) ),
                makeEl('div').attr( { 'id': 'graftedTrees', class: 'fCenter' } ) );

}

function createPieceTreeInfoContainer() {

    $('#treeInfoContainer').append(
        makeEl('div').attr( { 'id': 'pieceTreeContainer' } ).append(

            makeEl('div').attr( { 'id': 'pieceTreeTitle' } ).append(
                makeEl('div').attr( { 'class': 'fLeft rightMargin1' } ).text('Saved Tree Pieces'),
                makeEl('div').attr( { 'class': 'clear' } ) ),

            makeEl('div').attr( { 'id': 'pieceTreeHeader', 'class': 'fCenter greenBackground white' } ).append(
                    makeEl('div').attr( { 'class': 'leftMargin10 center fLeft width30' } ).text('name'),
                    makeEl('div').attr( { 'class': 'center fLeft width60' } ).text('comments'),
                    makeEl('div').attr( { 'class': 'clear' } ) ),
                makeEl('div').attr( { 'id': 'pieceTrees', class: 'fCenter' } ) ) );

}
